//
//  SitePayView.m
//  EasyToo
//
//  Created by Jr Lan on 13-9-1.
//
//

#import "SitePayView.h"

@implementation SitePayView
{
    id<paySiteViewDelegate> _sitedelegate;
    NSMutableArray *_allSiteInfo;
}

- (void)dealloc
{
    [_allSiteInfo release];
    _allSiteInfo = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame andDelegate:(id<paySiteViewDelegate>)sitedelegate
{
    _sitedelegate = sitedelegate;
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        SiteManager *sitemanager = [SiteManager shareManager];
        sitemanager.delegate = self;
        [sitemanager searchAllSiteInfo:@"1"];

        // 设置tableView的数据源
        self.dataSource = self;
        // 设置tableView的委托
        self.delegate = self;
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_allSiteInfo count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: nil];
    
    AllSiteInfo *siteInfo = [_allSiteInfo objectAtIndex:indexPath.row];
    //加载图像
    UIImageView *imgview  = [[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)]autorelease];
    NSURL *photourl = [NSURL URLWithString:siteInfo.sceneLogo];
    //url请求实在UI主线程中进行的
    UIImage *images = [UIImage imageWithData:[NSData dataWithContentsOfURL:photourl]];//通过网络url获取uiimage
    imgview.image = images;
    [cell.contentView addSubview:imgview];
    
    //加载名字
    UILabel *namelbl = [[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 220, 40)]autorelease];
    namelbl.text = siteInfo.sceneName;
    namelbl.font = [UIFont systemFontOfSize:15];
    namelbl.adjustsFontSizeToFitWidth = YES;
    [cell.contentView addSubview:namelbl];
    
    //加载描述
    UILabel *desclbl = [[[UILabel alloc]initWithFrame:CGRectMake(100, 50, 220, 40)]autorelease];
    desclbl.text = siteInfo.description;
    desclbl.font = [UIFont systemFontOfSize:10];
    desclbl.textColor = [UIColor lightGrayColor];
    desclbl.lineBreakMode = UILineBreakModeWordWrap;
    desclbl.numberOfLines = 0;
    [cell.contentView addSubview:desclbl];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 100;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [_sitedelegate clickPaySiteView:[_allSiteInfo objectAtIndex:indexPath.row]];
}

#pragma networking
- (void)qryAllSiteInfo:(BOOL)isSuccess
           AllSiteInfo:(NSMutableArray*)allSiteInfo
       TicketInfoArray:(NSMutableArray*)ticketInfoArray
{
    _allSiteInfo = allSiteInfo;
    [self reloadData];
}
@end
